package common.project.epic.ui;

import android.app.TabActivity;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.graphics.Color;
import android.os.Bundle;
import android.widget.TabHost;
import android.widget.TabHost.OnTabChangeListener;
import android.widget.TextView;

public class EpicMsgListTab extends TabActivity implements OnTabChangeListener {
	
	
	public static Context context;
	@Override
	public void onCreate(Bundle savedInstanceState) {
	    super.onCreate(savedInstanceState);
	    setContentView(R.layout.epicmsglisttab);

	    Resources res = getResources(); 
	    TabHost tabHost = getTabHost();
	    TabHost.TabSpec spec;
	    Intent intent;
	    Intent callingIntent;
	    tabHost.setOnTabChangedListener(this);
	    context = getApplicationContext();
	    callingIntent = getIntent();
	    if(callingIntent.getStringExtra("container") != null) {
	    	String container = callingIntent.getStringExtra("container");
	    	if(container.equalsIgnoreCase("cropUnread")) {
	    		intent = new Intent().setClass(this, EpicMsgList.class);
			    intent.putExtra("container", container);			    
			    spec = tabHost.newTabSpec("crop").setIndicator("Crop", res.getDrawable(R.drawable.ic_tabdrop)).setContent(intent);
			    tabHost.addTab(spec);
			    intent = new Intent().setClass(this, EpicMsgList.class);
			    intent.putExtra("container", "drop");
			    spec = tabHost.newTabSpec("drop").setIndicator("Drop", res.getDrawable(R.drawable.ic_tabcrop)).setContent(intent);
			    tabHost.addTab(spec);
			    intent = new Intent().setClass(this, EpicMsgList.class);
			    intent.putExtra("container", "quarantine");
			    spec = tabHost.newTabSpec("quarantine").setIndicator("Quarantine", res.getDrawable(R.drawable.ic_tabquarantine)).setContent(intent);
			    tabHost.addTab(spec);
			    tabHost.setCurrentTab(0);
	    	}
	    	else if(container.equalsIgnoreCase("drop")) {
	    		intent = new Intent().setClass(this, EpicMsgList.class);
			    intent.putExtra("container", "crop");
			    spec = tabHost.newTabSpec("crop").setIndicator("Crop", res.getDrawable(R.drawable.ic_tabdrop)).setContent(intent);
			    tabHost.addTab(spec);
			    intent = new Intent().setClass(this, EpicMsgList.class);
			    intent.putExtra("container", "drop");
			    spec = tabHost.newTabSpec("drop").setIndicator("Drop", res.getDrawable(R.drawable.ic_tabcrop)).setContent(intent);
			    tabHost.addTab(spec);
			    intent = new Intent().setClass(this, EpicMsgList.class);
			    intent.putExtra("container", "quarantine");
			    spec = tabHost.newTabSpec("quarantine").setIndicator("Quarantine", res.getDrawable(R.drawable.ic_tabquarantine)).setContent(intent);
			    tabHost.addTab(spec);
			    tabHost.setCurrentTab(1);
	    	}
	    }
	    else {
	    	intent = new Intent().setClass(this, EpicMsgList.class);
		    intent.putExtra("container", "crop");
		    spec = tabHost.newTabSpec("crop").setIndicator("Crop", res.getDrawable(R.drawable.ic_tabdrop)).setContent(intent);
		    tabHost.addTab(spec);
		    intent = new Intent().setClass(this, EpicMsgList.class);
		    intent.putExtra("container", "drop");
		    spec = tabHost.newTabSpec("drop").setIndicator("Drop", res.getDrawable(R.drawable.ic_tabcrop)).setContent(intent);
		    tabHost.addTab(spec);
		    intent = new Intent().setClass(this, EpicMsgList.class);
		    intent.putExtra("container", "quarantine");
		    spec = tabHost.newTabSpec("quarantine").setIndicator("Quarantine", res.getDrawable(R.drawable.ic_tabquarantine)).setContent(intent);
		    tabHost.addTab(spec);
		    tabHost.setCurrentTab(0);
	    }
	    setTabColor(tabHost);
//	    for(int i=0;i<tabHost.getTabWidget().getChildCount();i++)
//	    {
//		    final TextView tv = (TextView) tabHost.getChildAt(i).findViewById(android.R.id.title);        
//	    	tv.setTextColor(context.getResources().getColorStateList(R.drawable.text_tab_selector));
//	    }
	}

	@Override
	public void onTabChanged(String tabId) {
		
		setTabColor(this.getTabHost());
	}
	
	
	public static void setTabColor(TabHost tabhost) {
	    for(int i=0;i<tabhost.getTabWidget().getChildCount();i++)
	    {
	    	
	        tabhost.getTabWidget().getChildAt(i).setBackgroundColor(Color.parseColor("#ffffff")); //unselected
	    }
	    tabhost.getTabWidget().getChildAt(tabhost.getCurrentTab()).setBackgroundColor(Color.parseColor("#37c0a2")); // selected
	}
}
